﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using DataLayer;
using DataLayer.Generic;
using TestDataLayer;
namespace Tests
{
    [TestFixture]
    public class TestGenericRepository
    {
        [TestFixtureSetUp]
        public void SetUp()
        {

            ParentStaticRepository.DataContext.Parents.DeleteAllOnSubmit(ParentStaticRepository.SelectAll());
            ParentStaticRepository.SubmitChanges();
            ParentStaticRepository.DiscardDataContext();

            Parent p = new Parent { Name = "Parent1", Description=""};
            p.Children.Add(new Child { Name = "Child1", Description = ""});
            p.Children.Add(new Child { Name = "Child2", Description = ""});
            
            Parent p2 = new Parent { Name = "Parent2", Description = ""};
            p2.Children.Add(new Child {Name = "Child3", Description = ""});

            ParentStaticRepository.Insert(p);
            ParentStaticRepository.Insert(p2);
        }
        [Test]
        public void test_update_with_children()
        {
            var p1 = ParentStaticRepository.GetEntity(1);
            
            Child c = p1.Children[0];
            p1.Children.RemoveAt(0);
            //Product newP = new Product { ProductName = "Chang", SupplierID = 1, CategoryID = 1, QuantityPerUnit = "24 - 12 oz", UnitPrice = (decimal) 19.00, UnitsInStock = 17, UnitsOnOrder = 40, ReorderLevel = 25, Discontinued = false };
            //c1.Products.Add(newP);

            ParentStaticRepository.DiscardDataContext();
            ParentStaticRepository.Update(p1);

            ParentStaticRepository.DiscardDataContext();
            p1.Children.Add(c);
            ParentStaticRepository.Update(p1);
            //Assert.That(c1.CategoryName == c2.CategoryName && c1.CategoryID == c2.CategoryID, "Top level comparison failed");
            //Assert.That(c1.Products.Count == c2.Products.Count &&
            //    c1.Products[0].ProductID == c2.Products[0].ProductID &&
            //    c1.Products[0].CategoryID == c2.Products[0].CategoryID &&
            //    c1.Products[0].ProductName == c2.Products[0].ProductName, "Comparison of children failed");
        }
    }
}
